package io;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class Test {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("fos1.txt",true);
        File file = new File("fos1.txt");
        FileInputStream fis = new FileInputStream(file);
        String str = "往fos文本中写入数据！！！";
        byte[] data = str.getBytes(StandardCharsets.UTF_8);
        fos.write(data);
        str = "数据写入成功了！！！\n";
        data = str.getBytes(StandardCharsets.UTF_8);
        fos.write(data);

        byte[] fisData = new byte[(int) file.length()];
        fis.read(fisData);
        String sts = new String(fisData,StandardCharsets.UTF_8);
        System.out.println("读取到的数据是:"+sts);
        fos.close();
        fis.close();

       /* FileInputStream fis = new FileInputStream("image_cp.jpg");
        FileOutputStream fos = new FileOutputStream("image_cp1.jpg");
        byte[] data = new byte[1024*10];
        int line = 0;
        long start = System.currentTimeMillis();
        while((line =fis.read(data))!=-1){
            fos.write(data,0,line);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完成,耗时:"+(end-start)+"ms");
        fis.close();
        fos.close();*/
    }
}
